package com.yingxin.yxerp.module.appversion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yingxin.yxerp.module.appversion.entity.AppPush;
import com.yingxin.yxerp.module.appversion.mapper.AppPushMapper;
import com.yingxin.yxerp.module.appversion.service.IAppPushService;
import org.springframework.stereotype.Service;



@Service
public class AppPushServiceImpl extends ServiceImpl<AppPushMapper, AppPush> implements IAppPushService {
    /**
     * 根据username获取App
     * @param userName
     * @return
     */
    @Override
    public AppPush getVo(String userName) {
        QueryWrapper<AppPush> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AppPush::getUserName,userName);
        return getOne(queryWrapper);
    }

    @Override
    public AppPush getUserIdVo(String userId) {
        QueryWrapper<AppPush> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(AppPush::getUserId,userId);
        return getOne(queryWrapper);
    }

    /**
     * 创建app
     * @param appPush
     */
    @Override
    public void createVo(AppPush appPush) {
        if (!appPush.getAppId().isEmpty()){
            AppPush vo = getVo(appPush.getUserName());
            if (vo != null ){
                if (!vo.getAppId().equals(appPush.getAppId())){
                    updateById(appPush);
                }
            }else {
                save(appPush);
            }
        }
    }

    /**
     * 删除
     * @param userId
     */
    @Override
    public void remove(String userId) {
        removeById(userId);
    }


}
